package top.hiai.Controller.admin;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;

import top.hiai.interceptor.AdminInterceptor;
import top.hiai.model.ArcType;
import top.hiai.service.ArcTypeService;
import top.hiai.util.FormatjsonUtil;

/**
* @Author www.hiai.top
* @Email  goodsking@163.com
* @Message 更多资源尽在www.hiai.top,开发者：黄康权
* @Introduction 后台文章分类控制器
*/

public class AdminArticleTypeController extends Controller {

	ArcTypeService arcTypeService = new ArcTypeService();
	
	/**
	 * 后台的文章类别管理
	 */
	@Before(AdminInterceptor.class)
	public void arcTypeListTable(){
        Integer page = getParaToInt("page", 1);
        Integer limit = getParaToInt("limit", 10);
        Page<ArcType> paginate = arcTypeService.paginate(page, limit);
        renderJson(FormatjsonUtil.layuiPage(paginate));
	}
	/**
	 * 删除一个分类
	 */
	@Before(AdminInterceptor.class)
	public void deleteArcType(){
		arcTypeService.deleteById(getParaToInt());
		redirect("/admin/adminArticleTypeManage");
	}
	/**
	 * 添加分类信息
	 */
	public void saveArctileType(){
		//int tid = getParaToInt("id");
		String name = get("name");
		String remark = get("remark");
		int sort = getInt("sort");
		getModel(ArcType.class).setName(name).setRemark(remark).setSort(sort).save();
		renderJson("success",true);
	}
	/**
	 * 修改分类信息
	 */
	public void editArctileType(){
		int tid = getParaToInt("id");
		String name = get("name");
		String remark = get("remark");
		int sort = getInt("sort");
		getModel(ArcType.class).setTid(tid).setName(name).setRemark(remark).setSort(sort).update();
		renderJson("success",true);
	}
	/**
	 * 查找一个分类的信息
	 */
	public void findByType(){
		int tid = getParaToInt("id");
		ArcType arcType = arcTypeService.findById(tid);
		renderJson("result",arcType);
	}
}
